#include "staticBufferTest.h"

StaticBufferTest::StaticBufferTest( std::ostream &out, int verboseLevel ) :
	qunit( out, verboseLevel )
{

}

int StaticBufferTest::run()
{
	testMemorySize();
	testConversions();
	return qunit.errors();
}

void StaticBufferTest::testMemorySize()
{
	#ifdef __X86_64__
		const int WORDSIZE = 8;
	#elif defined( i386 )
		const int WORDSIZE = 4;
	#else
		const int WORDSIZE = 8;
	#endif

	std::string test = "This is a test"; //15B includes a trailing null character
	StaticBuffer ss1( test );
	StaticBuffer ss2;
	ss2.setString( test ); 

	QUNIT_IS_EQUAL( ss1.memorySize(), ss2.memorySize() );
	
	if( WORDSIZE == 4 )
	{
		//15B message + 4 for size_ + 8 for possible compiler stuff for dynamic 
		//allocation (assumes a 4 byte word) on a 64 bit machine this would be bigger. 
		QUNIT_IS_TRUE( ss1.memorySize() >= 31 ); 
	}
	else
	{
		QUNIT_IS_TRUE( ss1.memorySize() >= 47 );
	}

}

void StaticBufferTest::testConversions() 
{
	std::string test = "This is a test"; //14B
	StaticBuffer ss1( test );
	StaticBuffer ss2;
	ss2.setString( test ); 
	StaticBuffer ss3( ss1 );
	
	QUNIT_IS_EQUAL( ss1.toSTDString(), test );
	QUNIT_IS_EQUAL( ss2.toSTDString(), test );
	QUNIT_IS_EQUAL( ss3.toSTDString(), test );

}


